package com.scu.bank.web;
import com.scu.bank.core.jo.Result;
import com.scu.bank.core.jo.ResultGenerator;
import com.scu.bank.model.pojo.ResearchProject;
import com.scu.bank.service.ResearchProjectService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
* Created by pmeng on 2021/01/05.
*/
@RestController
@RequestMapping("/research/project")
public class ResearchProjectController {
    @Autowired
    private ResearchProjectService researchProjectService;

    @PostMapping("/add")
    public Result add(@RequestBody ResearchProject researchProject) {
        researchProjectService.addResearchProject(researchProject);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody List<String> ids) {
        if (ids == null){
            return ResultGenerator.genFailResult("请至少选择一项数据!");
        }
        researchProjectService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody ResearchProject researchProject) {
        researchProjectService.update(researchProject);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam String id) {
        ResearchProject researchProject = researchProjectService.getById(id);
        return ResultGenerator.genSuccessResult(researchProject);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageInfo<ResearchProject> pageInfo = researchProjectService.list(page, size);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    /**
     * 获取项目名称，id
     * @return
     */
    @GetMapping("getProject")
    public Result getProject(){
        return ResultGenerator.genSuccessResult(researchProjectService.getProject());
    }

    @GetMapping("getParentOrgIds")
    public Result getParentOrgIds(String orgId){
        return ResultGenerator.genSuccessResult(researchProjectService.getParentOrgIds(orgId));
    }
}
